home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / 80x0393.zip / DMA.TXT < prev    next >
Text File  |  1993-03-30  |  11KB  |  184 lines

  1. WHAT IS D.M.A.?
  2.  
  3. Consider the problem of moving a large amount of data to or from an I/O
  4. device.  This requirment is commonly encountered in the operation of many
  5. peripheral devices (disk drives, for example) that are constantly moving
  6. large amounts of data into and out of memory.  An ovious way of making
  7. the transfer would be a short program which for an input operation might
  8. read a byte from the I/O port into the accumulator (AX register) of the
  9. 8088 processor, and then move the data from the AX register to a memory
  10. location to store it.  In addition, we have to keep track of the memory
  11. locations where the data is going.  By far the simplest way of handling
  12. this is to lay the data down in continuous blocks locations within a block
  13. of memory, using one of the processor's index registers to control the
  14. address.  Each time a byte is transfered, the index register(usually the
  15. DI or Destination Index register) is incremented or decremented to point
  16. to the next location.  A typical example assembly language program to do
  17. this might be as follows:
  18.  
  19. -----------------------------------------------------------------------
  20.  
  21. SETUP:  MOV     AX,SEGMENT              ; setup segment of memory transfer
  22.  
  23.         MOV     DS,AX
  24.         MOV     DI,OFFSET               ; setup start address within segment
  25.  
  26.         MOV     CX,COUNT                ; setup # of bytes
  27.  
  28.         MOV     DX,IOPORT               ; DX = I/O port address
  29.  
  30. READ:   IN      AL,DX                   ; read byte from I/O port        (8)
  31.  
  32.         MOV     [DI],al                 ; store data                     (10)
  33.         INC     DI                      ; increment index                (2)
  34.         LOOP    READ                    ; continue till CX = 0           (17)
  35.  
  36. CONT:   ......                          ; yes, continue with program
  37.  
  38. ------------------------------------------------------------------------
  39.  
  40. The opposite oeration of transfering data from memory to an I/O port is
  41. essentually similar.  The numbers in parentheses following the READ: label
  42. are the number if processor clock cycles required to execute each instruction,
  43. with a total of 37 processor clock cycles required to execute the entire
  44. read segment.  On a standard IBM PC, the clock runs at 4.77 MHz, corresponding
  45. to a clock cycle period of 210 nanoseconds, and the loop takes 37 cycles or
  46. 7.8 microseconds to execute.  This would be the fastest we could transfer each
  47. byte.  Note also the following:
  48.  
  49. 1.  The processor is tied up 100% of the time in transferring data; it cannot
  50.     execute any other part of the program while the transfer is underway.
  51.  
  52. 2.  The rate at which the data is transferred is controlled by the processor
  53.     clock and may not correspond to the rate at which the I/O device wants
  54.     to handle the data.  This can be circumvented by polling the I/O device
  55.     to see if it is ready, or having the I/O device generate a hardware
  56.     interrupt; but either of these adds further code to the routine which
  57.     will slows down the transfer rate even further.  In practice because of
  58.     all the stacking of registers that occurs when a hardware intrrupt is
  59.     processed, it is impossible to handle data transfers rates much above
  60.     5 to 10 Khz using interrupts.
  61.  
  62. 3.  If the processor has to handle an interrupt from one device while it is
  63.     involved in handling a data transfer to another device then the delays
  64.     involved may cause it to miss data, or at least will cause the
  65.     discontinuitly in the data flow.
  66.  
  67.  
  68. It would be nice to have a way of transferring data without involving the
  69. processor so it can be freed up as much as possible to attend to execution
  70. of the program.  It wouldalso be a plus if we could speed the transfer rate
  71. up and be able to control the rate easily.  Since all we want to do is move
  72. a byte directly to/from an I/O port from/to memory without any sort of
  73. processing on the way,  we are better off not using the processor at all, but
  74. instead proving special hardware that will accomplish this commonly required
  75. task.  The process of connecting an I/O device directly to memory is known
  76. as Direct Memory Access (D.M.A.), and the hardware that controls this process
  77. is known as the D.M.A. controller, which the case of the IBM PC is the function
  78. of the 8237 chip on the system board.
  79.  
  80.  
  81.  
  82. THE MECHANICS OF A D.M.A. TRANSFER
  83.  
  84. What happens when a device wants to transfer data to/from memory?  The first
  85. step is for the device to send a signal known as a D.M.A. REQUEST (DREQ for
  86. short) to the D.M.A. controller.  The processor normally has control of the
  87. computer's address and data busses as well as control signals such as memory
  88. read/write (MEMR & MEMW) and I/O read/write (IOR & IOW) lines.  To accomplish
  89. a D.M.A. transfer, control of these lines must be passed to the D.M.A.
  90. controllers.  On receipt of the DREQ, the D.M.A. controller in turn issues
  91. a HOLD REQUEST to the processor.  As soon as it is able to, when it has
  92. partially completed the instruction it is currently executing, the processor
  93. issues a HOLD ACKNOWLEDGE signal to the D.M.A. controller, and simultaneously
  94. disconnects itself from the address, data and control busses.  This process
  95. is technically known as "TRI-STATING" as the connections to the processor
  96. assume a third, open circut state, compared to thier usual binary states of
  97. 1's and 0's or highs and lows.  On receipt of the HOLD ACKNOWLEDGE, the D.M.A.
  98. controller goes to work.  It realeases its own connections to the address and
  99. control busses from thier tristate condition, asserting a valid memory address
  100. from an internal counter and then issues a D.M.A. ACKNOWLEDGE (DACK) signal
  101. to the I/O device followed by a simultaneous IOW and MEMR for data outpu, or
  102. IOR and MEMW for input.  The perepheral in turn responds to the DACK and IOR
  103. or IOW signals by placing or recieving data on the data buss effecting a
  104. transfer directly to/from meory.  On completion of the MEMR/IOW or MEMW/IOW
  105. from the D.M.A. controller, the controller removes DACK, releases HOLD
  106. REQUEST, tristates its own address and control lines, and increments or
  107. decrements its internal address counter ready for the next transfer.  The
  108. processor in turn regains control of the busses, continuing execution execution
  109. of the next instruction.  From the assertion of the DREQ to completion of the
  110. cycle takes about 2 to 5 microseconds, depending on the length of the
  111. instruction that the processor happens to be engaged in on receipt of the
  112. DREQ.  The accual amount of time between instructions that the processor
  113. loses the buss to the D.M.A. controler is even less, about 1 microsecond.
  114. The effect on program execution is minimal even when transferring data at
  115. very high rates which can approach 350,000 bytes/sec on the IBM PC.  To
  116. prevent the D.M.A.  controller from 'hogging' the busses if the DREQ is
  117. held constantly high, the controller always allows the processor to perform
  118. at least part of an instruction between each D.M.A. transfer, so that even
  119. operating "flat-out", D.M.A. cannot grab much more than 30% of the buss
  120. bandwidth.
  121.  
  122. In order to perform D.M.A. operations, the perpheral must include hardware
  123. that generates the DREQ and responds to the DACK.  The D.M.A. controller, on
  124. the other hand, is a system component that is a standard feature of the IBM PC
  125. architecture.  Most compatibles also include the D.M.A. controller, with the
  126. execption of the TI Professional.
  127.  
  128. It is important to appreciate  that the D.M.A. controller sets the dunamics
  129. of the D.M.A. transfer,  that there is nothing in the peripheral I/O device
  130. that can alter the maximum speed at which the controller will handle data.
  131. There are some surpising side effects of this, in particular the IBM PC/AT,
  132. which is genrally 3 times faster than a standard PC or PC/XT, is actually
  133. slower at D.M.A. transfers because its controller operates at 3 MHz instead
  134. of 4.77 MHz on the PC.  On the other hand, it can also perform 16-bit
  135. transfers on its extended data buss, as well as 8-bit transfers on PC
  136. compatible section of its data buss which with the right hardware ca